<?php

namespace App\Http\Controllers\Cruise\Merchant;

use App\Http\Controllers\BaseController;
use App\Http\Validate\Cruise\CruiseCheckSelfTaskValidate;
use App\Service\Cruise\Check\CruiseCheckSelfTaskService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class CruiseCheckSelfTaskController extends BaseController
{
    /**
     * 门店自检列表
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function shopSelfCheckTaskList(Request $request): JsonResponse
    {
        $params = CruiseCheckSelfTaskValidate::shopSelfCheckTaskListValidate(
            $request->merge(["shopId" => $request->header("shopId") ?? 0])->all()
        );

        return $this->success(CruiseCheckSelfTaskService::shopSelfCheckTaskList($params));
    }

    /**
     * @param Request $request
     * @param int $id
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function shopSelfCheckTaskDailyDetail(Request $request, int $id): JsonResponse
    {
        $params = CruiseCheckSelfTaskValidate::shopSelfCheckTaskDetailValidate(
            $request->merge([
                "shopId" => $request->header("shopId") ?? 0,
                "id"     => $id
            ])->all()
        );

        return $this->success(CruiseCheckSelfTaskService::shopSelfCheckTaskDetail($params));
    }

    /**
     * 作废单一条任务
     *
     * @param Request $request
     * @param int $checkSelfDetailId
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function invalidSingleTask(Request $request, int $checkSelfDetailId): JsonResponse
    {
        $params = CruiseCheckSelfTaskValidate::invalidSingleTaskValidate(
            $request->merge([
                "shopId" => $request->header("shopId") ?? 0,
                "id"     => $checkSelfDetailId
            ])->all()
        );

        CruiseCheckSelfTaskService::invalidSingleTask($params, $request->user()->id);
        return $this->success();
    }

    /**
     * 门店自检列表
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function shopSelfCheckTaskListV2(Request $request): JsonResponse
    {
        $params = CruiseCheckSelfTaskValidate::shopSelfCheckTaskListV2Validate(
            $request->merge(["shopId" => $request->header("shopId") ?? 0])->all()
        );

        return $this->success(CruiseCheckSelfTaskService::shopSelfCheckTaskListV2($params));
    }
}
